Skip to content

Fix/tickerplant wdb - #776

Open
jaen15marcos wants to merge 6 commits into
DataIntellectTech:masterfrom
jaen15marcos:fix/tickerplant-wdb
Open

jaen15marcos wants to merge 6 commits into
DataIntellectTech:masterfrom
jaen15marcos:fix/tickerplant-wdb

Conversation

@jaen15marcos

@jaen15marcos jaen15marcos commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes four segmented-tickerplant bugs and two WDB end-of-day bugs, and the test suites that could not pass, did not write their results or depended on timing.

  • Tickerplant: end of day and end of period no longer turn logmsg into an empty table with another table’s columns; the logmsg log is closed on exit; a chained tickerplant that switches its logs on now writes to them; and a chained tickerplant advances nextperiod at each end of period.
  • WDB: in col mode the end-of-day merge wrote an empty partition and deleted the saved data, because the sort processes never got .merge.partsizes; and the default .save.postreplay stopped every end of day with 'rank.
  • Tests: the tickerplant, WDB, IDB, HDB, merge and schemas suites catch up with master (removed functions, changed schemas, -results instead of -testresults), and wait for processes and events instead of sleeping a fixed time. The third commit lists each suite.

Testing: every suite in tests/ on KDB-X, with the Starter Pack PR of this series: master passes 618 of 848 checks, master with this PR 948 of 1,055.

- End of day and end of period called .stpps.pubclear[.stplg.t]. That
  list is every table in the process, including logmsg, but pubclear
  resets each table from the publish schemas, which since DataIntellectTech#638 have no
  entry for logmsg. A dictionary of tables returns an empty copy of its
  first table for a key it does not have, so at every roll logmsg was
  quietly replaced by an empty table with another table's columns. The
  three calls now pass .stpps.t, as the batch code already does.

- The exit handler closed .stpps.t, the published tables, although a log
  is opened for every table in .stplg.logtabs. On a clean shutdown the
  logmsg log stayed open and its row in the meta table kept a null end
  time. It now closes .stplg.logtabs, the list end of day uses.

- A chained tickerplant that is not creating logs replaces the loghandles
  view with a dictionary of no-ops (DataIntellectTech#368). If it was then switched to
  create its own logs, they were opened but nothing was written to them,
  because loghandles was still that dictionary. The view is now restored
  when a chained tickerplant opens logs.

- At each end of period a chained tickerplant moved .stplg.currperiod on
  but never .stplg.nextperiod, so after its first roll nextperiod named
  the period that had just started. It now moves on with its parent: the
  new period plus the parent's period length.
…treplay

- Since partbyenum came in (DataIntellectTech#656), merge only merges the partitions
  listed in .merge.partsizes. The WDB still sent that table to the sort
  processes, and the sort process to its workers, only in part and hybrid
  mode. In col mode they had an empty table, so at end of day they wrote
  an empty partition to the HDB and deleted the saved data. merge/wdb did
  not catch it because its WDBs loaded their settings after wdb.q, so
  they saved in default mode and never took the merge path at all. The
  settings now load first.

- The default .save.postreplay was @[value;`postreplay;{[d;p] }]: when no
  postreplay is defined, the trap passes the error to its handler, so the
  default became a projection of {[d;p] } on the error string, and every
  end of day which called .save.postreplay[dir;date] stopped with 'rank
  (introduced by DataIntellectTech#762). The handler now returns the no-op function.
  stp/wdb partbyenum.csv triggers a WDB end of day and then checks the
  HDB; with the old default the trigger and both HDB checks failed. A new
  row calls the WDB's hook with (dir;date), as wdb.q does at end of day,
  so a regression fails with its cause named.
…not write results or depended on timing

Tickerplant suites:
- stp/pubsub: seven rows from DataIntellectTech#391 call rdbHandle, which the suite never
  defines. They now use the suite's own publisher, with one row that
  gives it trades to filter.
- stp/eod and three chained suites still called .stplg.stpeod, which DataIntellectTech#523
  folded into .stplg.endofday.
- stp/eod, stp/periodend and stp/chainedperiodend sized the meta table by
  the publish list, which is one short since DataIntellectTech#638.
- stp/tz upserted six values into the time zone table, which has had four
  columns since the tzinfo file was regenerated in DataIntellectTech#603.
- stp/custommode expected quote_iex, trade_iex and heartbeat, which the
  Starter Pack schema no longer has, so the suite now has its own schema
  file. It also moved the logs with setenv on KDBTPLOG, which the
  tickerplant has read once at start-up since DataIntellectTech#638; it now sets
  .stplg.kdbtplog. Its bad update is now a one-item list, the shape
  every update has, and its file count is compared by value.
- Seven run.sh passed -results where runtests.q reads -testresults, so
  those suites never wrote a results file; chainedeodlognone,
  chainedlogmodes and chainedrecovery also left $write out of their test
  command, so run.sh -w did not write theirs either.
- tests/helperfunctions.q: gethandle opened a new handle on every call and
  never closed the old one. A process has a limit on open connections,
  and stp/wdb reopened handles often enough to reach it.
- stp/batching: defbatch.csv resumed publication with .z.ts[] and checked
  the RDB's row count on the very next line, racing the asynchronous
  publish (it failed about one run in three). It now waits a second
  first, as membatch.csv does.
- stp/periodend and stp/chainedperiodend measured the period that was open
  when the test started. The chained tickerplant's starts when the test
  switches its logging on with .stplg.init, part-way through a period, so
  its length could never match; the plain tickerplant's first period
  starts when the process starts, so the check failed whenever no roll
  had happened yet. Both tests now wait for a roll first, so they measure
  a whole period. The check's comment said 1 microsecond; 1e6 nanoseconds
  is 1 millisecond.

WDB, IDB and HDB suites:
- stp/idbdefault and stp/idbpartbyenum queried quote_iex, which the
  Starter Pack schema no longer has, so the gateway returned an error
  string; they now query packets, which the tests never publish to. They
  also started the gateway with the IDBs and then slept 3 seconds, so the
  gateway's one attempt to connect could find an IDB not listening yet,
  and on a busy machine a handle could still be missing when the suite
  opened it. They now start the WDB, the HDB and the IDBs, wait until
  each accepts a connection, then start the gateway and wait until it
  has connected to them (waitforhandle and waitforgateway in
  tests/helperfunctions.q, up to 30 seconds each). idbdefault looked for
  today's partition with .z.D, the local date, where the WDB partitions
  by the UTC date, so it failed every evening west of UTC; it now uses
  .z.d. Both trigger a WDB end of day, which needs the .save.postreplay
  fix above.
- merge/tplogreplay loaded treplaysettings.q, but the file is
  tpreplaysettings.q, so its replays never ran partandmerge and the
  temp-directory checks failed. With the right file the checks still
  failed: they look at .replay.tempdir in the test process, which kept
  the default instead of the directory the replay uses. The test's
  settings now set it to that directory.
- wdb/intpartbyenum looked for today's partition with .z.D, the local
  date, where the WDB partitions by the UTC date, so it failed every
  evening west of UTC; it now uses .z.d.
- schemas checked quote_iex and trade_iex against the application's
  schema file, which no longer has them. Like stp/custommode, it now has
  its own schema file. It also wrote into and loaded the Starter Pack's
  sample HDB, whose 2015 partitions do not have the suite's newer
  tables, so the HDB could only start where reading those tables is
  left until a query asks for them. The suite now writes and loads its
  own HDB, which run.sh removes at the end.
- stp/wdb: singlelog, tabperiod and tabular load the sym list the WDBs
  enumerated against before loading the saved partitions, and partbyenum
  reads the HDB folder with the query ".wdb.hdbsettings`hdbdir" instead of
  sending (`.wdb.hdbsettings;`hdbdir), which applies a dictionary as if it
  were a function.

Timing:
- stp/chainedlogmodes waits 11 seconds on a 10-second period and expects
  exactly one end of period. A wait that began in the last second of a
  period held two, and the suite failed rows 21 and 43 (about one run in
  ten). Each wait now begins straight after an end of period reaches the
  RDB, and the RDB's count is reset there, so the wait holds exactly one;
  row 43 checks the count since that reset.
A chained tickerplant in loggingmode none or parent (the Starter Pack's
sctp1) opens no logs, so it never sets .stplg.dldir. At end of day
.stplg.dayrollover still closed its logs: the meta update failed with
'.stplg.dldir, and the rest of the rollover did not run. The process
logged the error at every end of day, and was not
reinitialised, so its message and row counts (.stplg.msgcount, and
.stplg.rowcount, which subdetails gives subscribers as rowcounts) and
.stplg.seqnum carried on from the day before. Its date had already moved
on, and its subscribers had the end of day.

.stplg.haslogs is the condition init opens logs on: createlogs, or
loggingmode create. dayrollover closes the day's logs only where it
holds, and so does .z.exit, which skipped only a chained tickerplant not
in create mode: a tickerplant with createlogs off failed the same way,
at end of day and on exit.

tests/stp/chainedeodlognone checks that the chained tickerplant counted
the first updates, and that its counts start again from 0 after the end
of day.
loghandles::exec tbl!handle from currlog
// Re-establish the view above. A chained tickerplant which is not creating logs replaces it with a dictionary of
// no-ops (see init); without this, switching that process to create its own logs opened them but wrote nothing
restoreloghandles:{value "loghandles::exec tbl!handle from currlog"};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this run through value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already done in chainedrecovery testing: it sends that line to the sctp as a string before changing mode.

before,0,0,q,sctpHandle"loghandles::exec tbl!handle from currlog",1,,"resetting loghandles definition for change of mode"

q)currlog:([tbl:`symbol$()]logname:`symbol$();handle:`int$())
q)loghandles::exec tbl!handle from currlog
q)views[]
,`loghandles
q)`..loghandles set `trade`quote!2#enlist(::);      / what init does on an sctp that creates no logs
q)views[]
`symbol$()
q){loghandles::exec tbl!handle from currlog}[];     / the same line inside a function: still not a view
q)views[]
`symbol$()
q){value "loghandles::exec tbl!handle from currlog"}[]
q)views[]
,`loghandles

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably just use set instead of ::?
`loghandles set exec tbl!handle from currlog
Better practice for setting globals and should get around it not setting within the function

// eop log roll is stopped if eod is also going to be triggered (roll is not stopped in SCTP)
stpeoperiod:{[currentpd;nextpd;data;rolllogs]
.lg.o[`endofperiod;"flushing remaining data to subscribers and clearing tables"];
.stpps.pubclear[.stplg.t];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we double check these changes from .stplg.t to .stpps.t - double confirm the old one is wrong (these feels a bit like something that should've bitten us before now)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.stplg.t is every table in the process except currlog

t::tables[`.]except `currlog;
so it includes logmsg. .stpps.t is the list of published tables, and since #638 it leaves logmsg out (https://github.com/DataIntellectTech/TorQ/pull/638/changes#diff-da8abe6e04ad1dd510c60b90806a4e4c94d7ff7ea63c4622066a87cf7b866297R36). Before #638 the two lists were the same, so these three calls were right when they were written. They have been wrong ever since.

pubclear publishes each table it is given and then resets it from the publish schemas.

pubclear:{
.stpps.pub'[x;value each x,:()];
@[`.;x;:;.stpps.schemasnoattributes[x]];
}
Those schemas have no entry for logmsg, and a dictionary of tables returns an empty copy of its first table for a key it does not have. So at every end of period and end of day the tickerplant's logmsg is replaced by an empty table with the columns of the first published table.

/ after: with PR
q)h:hopen `::6500:admin:admin
q)h"cols logmsg"
`time`sym`proctype`host`loglevel`id`message
q)h".stpps.pubclear[.stpps.t]"
q)h"cols logmsg"
`time`sym`proctype`host`loglevel`id`message
q)h"`logmsg insert (.z.p;`stp1;`segmentedtickerplant;.z.h;`ERR;`test;\"a log message\")"
,0

/ before: master
q)h".stpps.pubclear[.stplg.t]"
q)h"cols logmsg"
`time`sym`src`dest`srcport`destport`seq`ack`win`tsval`tsecr`flags`protocol`length`len`data
q)h"`logmsg insert (.z.p;`stp1;`segmentedtickerplant;.z.h;`ERR;`test;\"a log message\")"
'length
  [0]  h"`logmsg insert (.z.p;`stp1;`segmentedtickerplant;.z.h;`ERR;`test;\"a log message\")"

jaen15marcos and others added 2 commits November 30, 2026 10:35
dbwriteutils.q: .save.postreplay's default is master's line again. DataIntellectTech#786
fixed the same default on master with {{[d;p] }}; this branch had
{[e] {[d;p] }}, which does the same. Using master's line leaves
dbwriteutils.q unchanged by this branch.

rdb.q: restoretimeout restores the timeout only where timeoutreset has
saved one. timeoutreset runs from a timer one minute before the
scheduled roll, so an end of day which that timer did not prepare (one
forced on the tickerplant) stopped the RDB's reload on an undefined
.rdb.timeout, and the RDB kept the day's rows.

tests/schemas/run.sh: the suite stops its processes and starts them
again straight away, and torq.sh start skips a process that is still
running. A tickerplant that took a moment to exit was therefore missing
for the second half of the suite, and its five tickerplant checks
failed. run.sh now waits, ten seconds at most, until the processes have
stopped.
@chris-brown26

Copy link
Copy Markdown

Testing: every suite in tests/ on KDB-X, with the Starter Pack PR of this series: master passes 618 of 848 checks, master with this PR 948 of 1,055.

Are the ones still failing verified and are all the tests touched in this PR now passing?

@jaen15marcos

Copy link
Copy Markdown
Contributor Author

Testing: every suite in tests/ on KDB-X, with the Starter Pack PR of this series: master passes 618 of 848 checks, master with this PR 948 of 1,055.

Are the ones still failing verified and are all the tests touched in this PR now passing?

Yes, this PR alone makes 618/848 -> 948/1,055. All my PRs together fix all issue

@jaen15marcos jaen15marcos reopened this Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants